local skel = fk.CreateSkill {
  name = "emo__lingqiao",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__lingqiao"] = "灵巧",
  [":emo__lingqiao"] = "锁定技，跳过你的判定阶段；你的点数大于9的锦囊牌视为【无中生有】；你的手牌上限+X（X为你的回合内进入弃牌堆的花色数）。",

  ["@emo__lingqiao-turn"] = "灵巧",
}

skel:addEffect(fk.EventPhaseChanging, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and data.phase == Player.Judge
  end,
  on_use = function(self, event, target, player, data)
    player:skip(Player.Judge)
    return true
  end,
})

skel:addEffect(fk.AfterCardsMove, {
  anim_type = "drawcard",
  can_refresh = function(self, event, target, player, data)
    return player.room.current == player and player:hasSkill(skel.name, true) and #player:getTableMark("@emo__lingqiao-turn") < 4
  end,
  on_refresh = function(self, event, target, player, data)
    local mark = player:getTableMark("@emo__lingqiao-turn")
    for _, move in ipairs(data) do
      if move.toArea == Card.DiscardPile then
        for _, info in ipairs(move.moveInfo) do
          if Fk:getCardById(info.cardId).suit ~= Card.NoSuit then
            table.insertIfNeed(mark, Fk:getCardById(info.cardId):getSuitString(true))
          end
        end
      end
    end
    player.room:setPlayerMark(player, "@emo__lingqiao-turn", mark)
  end
})

skel:addEffect("maxcards", {
  correct_func = function(self, player)
    return player:hasSkill(skel.name) and #player:getTableMark("@emo__lingqiao-turn") or 0
  end,
})

skel:addEffect("filter", {
  card_filter = function (self, card, player, isJudgeEvent)
    return card.type == Card.TypeTrick and card.number > 9
    and player:hasSkill(skel.name) and table.contains(player:getCardIds("h"), card.id)
  end,
  view_as = function (self, player, card)
    local c = Fk:cloneCard("ex_nihilo", card.suit, card.number)
    c.skillName = skel.name
    return c
  end,
})

return skel
